package com.jokins.common.util.date;

import java.util.regex.Pattern;

/**
 * 〈〉<br>
 * 账号类型验证
 * @author Mr.Wang
 * @create 2025/2/5
 */
public class InputValidator {

    // 正则表达式模式，用于匹配手机号（简单示例，可根据实际需求调整）
    private static final String PHONE_PATTERN = "^[0-9]{10,15}$";
    // 正则表达式模式，用于匹配电子邮件地址
    private static final String EMAIL_PATTERN = "^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$";

    /**
     * 判断输入的字符串是手机号还是电子邮件地址
     *
     * @param input 输入的字符串
     * @return 如果是手机号，返回 "Phone"；如果是电子邮件地址，返回 "Email"；否则返回 "Unknown"
     */
    public static String checkInputType(String input) {
        if (input == null || input.isEmpty()) {
            return "Unknown";
        }

        if (Pattern.matches(PHONE_PATTERN, input)) {
            return "Phone";
        } else if (Pattern.matches(EMAIL_PATTERN, input)) {
            return "Email";
        } else {
            return "Unknown";
        }
    }

    public static void main(String[] args) {
        // 测试手机号
        String phoneNumber = "1234567890";
        System.out.println(phoneNumber + " is " + checkInputType(phoneNumber));

        // 测试电子邮件地址
        String emailAddress = "test@example.com";
        System.out.println(emailAddress + " is " + checkInputType(emailAddress));

        // 测试其他字符串
        String otherString = "invalidinput";
        System.out.println(otherString + " is " + checkInputType(otherString));
    }
}